module asound
import StdEnv, japi

/* This example shows how to play a sound file. 
   If you press the button [Marseillaise], you 
   will hear the beautiful French Anthem. You can
   also type an au-format file name on the edit
   field and press the button [exec] to hear 
   the corresponding sound. */

Start world
  # (js, world) = begin_japi world
    (frm, js) = jnewFrame(XYWH 100 150 400 300) "Sound" js
    (txt, js) = jnewTextArea (XY 20 100)  3 40 frm  js
    txt = jsetfont (TimesNew 20) txt
    (btx, js) = jnewButton(XYWH 20 50 90 30) "exec" frm js
    (allons, js) = jnewButton(XYWH 120 50 90 30) "Marseillaise" frm js
    (frm, js) = jshow frm js
    js= loop txt js
         with
           loop :: !TDev  !JapiState -> JapiState
           loop txt  js
              # (na, js) = jnextaction js
              | na== (act frm) = jquit js
              | na== (act btx)
                    # (txt, js)= jplaysound txt (jgetText txt) js
                    = loop txt  js
              | na== (act allons)
                   # (txt, js)= jplaysound txt "marseillaise.au" js
                   = loop txt  js
              | otherwise= loop txt  js
  = end_japi js world

    
    
 